import jwt
from datetime import datetime


class TokenAuth:

    def create_token(self, payload):
        '''
        创建令牌
        :param payload:
        :return:
        '''
        pass

    def verify_token(self, token):
        '''
        验证令牌
        :param token:
        :return:
        '''
        pass

    def refresh_token(self, token):
        pass


token = jwt.encode({'exp': datetime.utcnow()}, 'test', algorithm='HS256')

_token = b'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MTY3NzA2MjR9.q4rXYHMHn2qnevcIjXqijiidXfV22XoUdEQzoU2lAbo'

try:
    result = jwt.decode(_token, 'test', algorithms=['HS256'])
except jwt.ExpiredSignature:
    print('过期');
except jwt.DecodeError:
    print('格式错误')
except jwt.InvalidAlgorithmError:
    print('无效秘钥')
